{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09ca9221",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Execute this cell to install dependencies\n",
    "%pip install sf-hamilton[visualization,slack]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5efeed20",
   "metadata": {},
   "source": [
    "# Slack notifier [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/dagworks-inc/hamilton/blob/main/examples/slack/notebook.ipynb) [![GitHub badge](https://img.shields.io/badge/github-view_source-2b3137?logo=github)](https://github.com/apache/hamilton/blob/main/examples/slack/notebook.ipynb)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da2854cc",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "from hamilton import driver\n",
    "from hamilton.plugins.h_slack import SlackNotifier\n",
    "\n",
    "# load magic\n",
    "%load_ext hamilton.plugins.jupyter_magic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb94a097",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%cell_to_module -m example_module\n",
    "def test_function() -> pd.DataFrame:\n",
    "    raise Exception(\"test exception\")\n",
    "    return pd.DataFrame({\"a\": [1, 2, 3], \"b\": [4, 5, 6]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d7f2aa0",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# SLACK DETAILS FOR YOU TO FILL IN\n",
    "api_key = \"YOUR_API_KEY\"\n",
    "channel = \"YOUR_CHANNEL\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff78bcf7",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "dr = (\n",
    "    driver.Builder()\n",
    "    .with_modules(example_module)\n",
    "    .with_adapters(SlackNotifier(api_key=api_key, channel=channel))\n",
    "    .build()\n",
    ")\n",
    "print(dr.execute([\"test_function\"]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
